<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;

class Admins extends Model
{
	//表名
	protected  $table = 'zzz_admins';
	//白名单
	protected $fillable = ['name','phone','address','createtime','lastdotime']; 
	//有时间字段不自动更新手动更新
	public $timestamps = false;
	//查询
	public function getAdmins($in_search)
	{
			$query = $this->select('*');
			if(!empty($in_search)){
				 	$query->where(function($query)use($in_search){
					$query->where('name','like','%'.$in_search.'%')
						  ->orwhere('phone','like','%'.$in_search.'%');
				});
			}
			$rows = $query->orderBy('id','desc')->paginate(5);

			if(!empty($rows)){
				return $rows;
			}
			return [];
	}


	//查询表中所有数据
	// public function getAdmins($in_search)
	// {
	// 	// if(empty($in_search)){
	// 	// 	return $this->select('*')->orderBy('id', 'desc')->paginate(5);
	// 	// }
	// 		// return $this->where('name','like','%'.$in_search.'%')->paginate(5);
	// 		$query = $this->select('*');
	// 		if(!empty($in_search)){
	// 			$query->where('name','like','%'.$in_search.'%');
	// 		}
	// 		$rows = $query->orderBy('id','desc')->paginate(5);

	// 		if(!empty($rows)){
	// 			return $rows;
	// 		}
	// 		return [];
	// }


	//添加一条数据
	public function addOne($name='',$phone='',$address='',$createtime='',$lastdotime='')
	{
		
		return  $this->create(['name'=>$name,'phone'=>$phone,'address'=>$address,
			'createtime'=>$createtime,'lastdotime'=>$lastdotime]);
		
	}
	//删除一条数据
	public function delOne($id=0){
		return $this->where('id',$id)->delete();

	}
	//根据id查询一条数据
	public function getOneById($id=0){
		return $this->where('id',$id)->first();
	}
	//更新数据
	public function renew($id='',$name='',$phone='',$address='',$lastdotime=''){
		return $this->where('id',$id)->update(['name'=>$name,'phone'=>$phone,
			'address'=>$address,'lastdotime'=>$lastdotime]);
		
	}

	//Home
	//根据用户姓名查询用户
	public function getUserByNmae($name=''){
		if (!empty($name)) {
			return $this->where('name',$name)->first();
		} else {
			return '';
		}
		

	}

}

















?>